generate :: ([a] -> Bool) -> ([a] -> a) -> [a]generate stop next = generateFrom' stop next []generateFrom :: ([a] -> Bool) -> ([a] -> a) -> [a] -> [a]generateFrom stop next xs 	| stop xs = xs							| otherwise = generateFrom stop next (xs ++ [next xs])							generateBase :: ([a] -> Bool) -> a -> (a -> a) -> [a]generateBase stop base next = generate stop (\lista -> case lista of														[] -> base														l -> next (last l))														factoriales :: Int -> [Int]factoriales n = generate longitudDeListaMayorOIgualAN (\l -> case l of 														[] -> 1														l -> last l * (length l + 1))						where						longitudDeListaMayorOIgualAN l = length l >= n						iterateN :: Int -> (a -> a) -> a -> [a]iterateN n next base = generateBase (\l -> length l >= n) base nextgenerateFrom' :: ([a] -> Bool) -> ([a] -> a) -> [a] -> [a]generateFrom' stop next xs = last(takeWhile (not . stop) (iterate (\l -> l ++ [next l]) xs))